package com.hb.ssmdemo.tools;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
/**
 * 
*@ClassName:PinYinUtils   
*@Description:将汉字转为拼音工具类 
*@author: zxq
*@date：Sep 25, 2012 4:22:29 PM   
*@Modified By(修改�?)�?
*@Modified time(修改时间)：Sep 25, 2012 4:22:29 PM  代码与注释同步修�?   
*@Modify Description(修改备注)�? 代码修改具体内容说明 
*@version V1.0
 */
public class PinYinUtils {


    public static  String toPinYin(String hanzis){
        CharSequence s= hanzis;
        
        char [] hanzi=new char[s.length()];
        for(int i=0;i<s.length();i++){
        	hanzi[i]=s.charAt(i);
        }
        
        char [] t1 =hanzi; 
        String[] t2 = new String[s.length()];
        /** *//**
         * ��������ʽ
         */
        net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat t3 = new
        HanyuPinyinOutputFormat();
        t3.setCaseType(HanyuPinyinCaseType.LOWERCASE);
        t3.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
        t3.setVCharType(HanyuPinyinVCharType.WITH_V);
        
        int t0=t1.length;
        String py = "";
        try {
            for (int i=0;i<t0;i++)
            {
                t2 = PinyinHelper.toHanyuPinyinStringArray(t1[i], t3);
                py=py+t2[0].toString();
                    }
        }
        catch (BadHanyuPinyinOutputFormatCombination e1) {
            e1.printStackTrace();
        }
        
        return py.trim();
        }
    
    
    
    public static void main(String[] args) {
        
        System.out.println(PinYinUtils.toPinYin("张小"));
    }
 
}